package com.dbh.company.freeform.sensitive;

import cn.hutool.http.HttpRequest;
import cn.hutool.json.JSONUtil;
import com.dbh.company.econtract.BatchUpdateParam;

/**
 * 调用协议平台接口刷数据操作
 * @author dongbanghui
 * @create 2023/7/6
 */
public class RemoteOperate {

    /**
     * 更新cp_seal_info表中摘要字段
     * @param batchUpdateParam 范围参数
     * @return 执行结果
     */
    public static String batchUpdateCPSealInfo(BatchUpdateParam batchUpdateParam, String domain) {
        String url = domain + "/manualFlushed/batchUpdateCPSealInfo";
        return batchUpdateData(url, batchUpdateParam);
    }

    /**
     * 更新cf_attachment_third_relation表中摘要字段
     * @param batchUpdateParam 范围参数
     * @return 执行结果
     */
    public static String batchUpdateCfAttachmentThirdRelation(BatchUpdateParam batchUpdateParam, String domain) {
        String url = domain + "/manualFlushed/batchUpdateCfAttachmentThirdRelation";
        return batchUpdateData(url, batchUpdateParam);
    }

    /**
     * 更新cp_saas_send_msg_detail_log表中摘要字段
     * @param batchUpdateParam 范围参数
     * @return 执行结果
     */
    public static String batchUpdateCpSaasSendMsgDetailLog(BatchUpdateParam batchUpdateParam, String domain) {
        String url = domain + "/manualFlushed/batchUpdateCpSaasSendMsgDetailLog";
        return batchUpdateData(url, batchUpdateParam);
    }

    /**
     * 校验cp_seal_info表中摘要字段
     * @param batchUpdateParam 范围参数
     * @return 执行结果
     */
    public static String batchSelectCPSealInfo(BatchUpdateParam batchUpdateParam, String domain) {
        String url = domain + "/manualFlushed/batchSelectCPSealInfo";
        return batchUpdateData(url, batchUpdateParam);
    }

    /**
     * 校验cf_attachment_third_relation表中摘要字段
     * @param batchUpdateParam 范围参数
     * @return 执行结果
     */
    public static String batchSelectCfAttachmentThirdRelation(BatchUpdateParam batchUpdateParam, String domain) {
        String url = domain + "/manualFlushed/batchSelectCfAttachmentThirdRelation";
        return batchUpdateData(url, batchUpdateParam);
    }

    /**
     * 更新数据
     * @param url 更新数据的url
     * @param batchUpdateParam 范围参数
     * @return 执行结果
     */
    public static String batchUpdateData(String url, BatchUpdateParam batchUpdateParam) {
        return HttpRequest.post(url)
                .header("X-Requested-With", "XMLHttpRequest")
                .header("Cookie", "JSESSIONID=68f4f705-fd79-4bc2-97dd-e8fa7c938fae")
                .contentType("application/json;charset=UTF-8")
                .body(JSONUtil.toJsonStr(batchUpdateParam))
                .execute().body();
    }
}
